//
// Created by liushuai on 2020/3/25.
//

#include "levelOrder.h"
vector<vector<int> > levelOrder(TreeNode* root) {
    queue<TreeNode*> current;
    vector<vector<int>>result;
    if (root){
        current.push(root);
        while (!current.empty()){
            int count = current.size();
            vector<int> layers;
            while (count){
                TreeNode* node = current.front();
                current.pop();
                layers.push_back(node->val);
                if(node->left)
                    current.push(node->left);
                if(node->right)
                    current.push(node->right);
                count--;
            }
            if(layers.size()>0)
                result.push_back(layers);

        }

    }
    return result;
}